package com.doyens.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doyens.domain.Admin;
import com.doyens.mapper.AdminMapper;
import com.doyens.result.Result;
import com.doyens.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper,Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Result loginList(Admin admin2) {
             if(admin2==null){
                 return null;
             }

            if(admin2.getAname()==null||admin2.getPassword()==null){
                return new Result().setMsg("用户名或密码为空");
            }
        LambdaQueryWrapper<Admin> wrapper=new LambdaQueryWrapper<>();
            wrapper.eq(Admin::getAname,admin2.getAname());
        Admin admin1 = adminMapper.selectOne(wrapper);
        if(admin1==null){
                 return new Result().setMsg("用户名不正确");
           }
           if(admin2.getPassword()==null){
               return new Result().setMsg("密码错误");
           }
           String token= UUID.randomUUID().toString();
        HashMap<String, Object> map = new HashMap<>();
        admin2.setPassword("*****");
        map.put("user",admin1);
        map.put("token",token);
        return new Result("查询成功",true,20000);
    }
}
